<?php

namespace App\Http\Controllers;

use App\Services\OSS;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Eloquent\Model;
class ServiceController extends Controller
{
    use \App\Traits\ApiTrait, \App\Traits\SessionTrait, \App\Traits\AjaxTrait, \App\Traits\DbTrait, \App\Traits\UserTrait;
    public $curl;
    public function __construct() {
		$this->curl = new \Ixudra\Curl\CurlService();
	}
  public function getAppVersion(request $request){
    $state=0;
    $DBData=DB::table('app_ver')->orderby('id','desc')->first();
    $ver=$DBData->ver;
    $url=$DBData->url;
    $oldver=$request->ver;
    if($ver>$oldver)$state=1;
    $result=[
      'ver' => $ver,
      'url' => $url,
      'state'=>$state
  ];
    return json_encode($result);
  }

  public function updateAppVersion(request $request){
      // Start transaction!
      DB::beginTransaction();
      try {
        $ver=$request->ver;
        $url=$request->url;
        DB::insert("insert into app_ver (ver,url) values ('$ver','$url')");
        $status=1;
      }
      catch(\Exception $e)
      {
          DB::rollback();
          $status=0;
      }
      DB::commit();
      return json_encode(['status'=>$status]);
  }

}
